﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//
using Mmht.BT;

public partial class admin_xsgl_tjyzzh : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["admin_id"] == null)
        {
            Response.Redirect("admin_logout.aspx");
            return;
        }
    }
    protected void btAdd_Click(object sender, EventArgs e)
    {
        string tag = this.tbTag.Text.Trim();
        string beginNumber = this.tbAcountBeging.Text.Trim();
        string endNumber = this.tbAcountEnd.Text.Trim();
        string pwdTag = this.tbPwd.Text.Trim();
        int begin = 0;
        int end = 0;
        try
        {
            begin = int.Parse(beginNumber);
        }
        catch
        {
            message_show("起始账号必须为数字");
            return;
        }
        try
        {
            end = int.Parse(endNumber);
        }
        catch
        {
            message_show("结束账号必须为数字");
            return;
        }
        if (begin < 0 || end < 0 || begin > end)
        {
            message_show("您输入的账号区间不合法");
            return;
        }
        AdminBT at = new AdminBT();
        StudentBT st = new StudentBT();
        int id = int.Parse(Session["admin_id"].ToString());
        string created_by = at.FindbyId(id);
        int n = 0;
        for (int i = begin; i <= end; i++)
        {
            string account = tag.Trim() + i.ToString();
            string password = pwdTag.Trim() + account;
            if (!st.checkAccountExist(account))
            {
                st.InsertStudent(account, password, created_by);
                n++;
            }
        }
        message_show("已成功添加" + n.ToString() + "组账号和密码");
    }

    /// <summary>
    /// 信息提示
    /// </summary>
    /// <param name="msg">提示信息</param>
    private void message_show(string msg)
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "信息提示", "<script language='javascript'>  warning('" + msg + "');</script>");
    }
}
